package com.jader.adapter;

import java.util.ArrayList;
import java.util.List;

import com.jader.beans.LunTan_huati_Bens;
import com.jader.util.JaderApplication;
import com.lidroid.xutils.BitmapUtils;
import com.zlp.jader.R;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyAdapter_huati extends BaseAdapter {
	// 通过构造器获取数据来源
	public List<LunTan_huati_Bens> list = new ArrayList<LunTan_huati_Bens>();
	// 接收上下文参数，以便了解是哪个activity在调用
	Context context;
	// 用来初始化布局文件，可以把一个xml布局转换为对应的android对象view
	LayoutInflater mInflater;
	// ViewHolder viewHolder;
	private BitmapUtils bitmapUtils;

	public MyAdapter_huati(List<LunTan_huati_Bens> list, Context context) {
		super();
		this.list = list;
		this.context = context;
		mInflater = LayoutInflater.from(context);
		bitmapUtils = JaderApplication.getBitmapUtils();
		bitmapUtils.configDefaultLoadingImage(R.drawable.pic_item_list_default);
	}

	public void onDateChange(List<LunTan_huati_Bens> list) {
		this.list = list;
		this.notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		// 数据总量
		return list.size();
	}

	public List<LunTan_huati_Bens> getList() {
		return list;
	}

	public void setList(List<LunTan_huati_Bens> list) {
		this.list = list;
	}

	@Override
	public Object getItem(int position) {
		// 返回每一行的数据
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// 返回每一行的id，几乎很少用到，列表的索引号，从零开始
		return position;
	}

	@Override
	public int getItemViewType(int position) {
		int result = 0;
		return result;
	}

	@Override
	public int getViewTypeCount() {
		// TODO Auto-generated method stub
		return 2;
	}

	@SuppressLint("InflateParams")
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// MyListener myListener = null;
		// 告知列表每一行的布局样式，同时制定每一行的数据来自哪里
		// position：列表的索引，从0开始，convertView是每一行的布局，parent每一行的父布局，没有就是null
		/*
		 * if (convertView == null) { convertView =
		 * mInflater.inflate(R.layout.item_luntan_topic_fragment, null);
		 * 
		 * // 初始化每一行的控件 viewHolder = new ViewHolder();
		 * viewHolder.zhanshiImageView = (ImageView) convertView
		 * .findViewById(R.id.huati_biaotiimageview);
		 * 
		 * viewHolder.themeTextView = (TextView) convertView
		 * .findViewById(R.id.huati_biaoti); viewHolder.huatitextTextView =
		 * (TextView) convertView .findViewById(R.id.huati_neirong);
		 * convertView.setTag(viewHolder);
		 * 
		 * } else { viewHolder = (ViewHolder) convertView.getTag(); }
		 */
		convertView = mInflater.inflate(R.layout.item_luntan_topic_fragment,
				null);

		// 初始化每一行的控件
		ImageView zhanshiImageView = (ImageView) convertView
				.findViewById(R.id.huati_biaotiimageview);

		TextView themeTextView = (TextView) convertView
				.findViewById(R.id.huati_biaoti);
		TextView huatitextTextView = (TextView) convertView
				.findViewById(R.id.huati_neirong);

		// String redID = list.get(position).getUserBens().getPicture();
		if (list.get(position).getList() != null
				&& list.get(position).getList().size() > 0) {
			String url = list.get(position).getList().get(0);
			bitmapUtils.display(zhanshiImageView, JaderApplication.getIP()
					+ url);

		}

		final String text = list.get(position).getContent();
		huatitextTextView.setText(text);

		final String text1 = list.get(position).getTheme();
		themeTextView.setText(text1);

		return convertView;

	}

	class ViewHolder {
		ImageView zhanshiImageView;
		TextView huatitextTextView, themeTextView;// 主题
	}
}